package rnn.utilities;

public abstract class Element {

	public float[][] points;

	public abstract float sim(Element cluster);

	public float sim(float[] p1, float[] p2) {

		// float sum = 0;
		// for (int i = 0; i < p1.length; i++) {
		// sum += Math.pow(p2[i] - p1[i], 2);
		// }
		//
		// return (float) Math.sqrt(sum);

		float scalar = 0;
		float lenght1 = 0;
		float lenght2 = 0;
		for (int i = 0; i < p1.length; i++) {
			lenght1 += Math.pow(p1[i], 2);
			lenght2 += Math.pow(p2[i], 2);
			scalar += p2[i] * p1[i];
		}

		lenght1 = (float) Math.sqrt(lenght1);
		lenght2 = (float) Math.sqrt(lenght2);

		if (lenght1 == 0 || lenght2 == 0)
			return 0;

		return scalar / (lenght1 * lenght2);

	}

	public float sim(float[] p1,float lenght1, float[] p2, float lenght2) {

		// float sum = 0;
		// for (int i = 0; i < p1.length; i++) {
		// sum += Math.pow(p2[i] - p1[i], 2);
		// }
		//
		// return (float) Math.sqrt(sum);

		float scalar = 0;

		for (int i = 0; i < p1.length; i++) {

			scalar += p2[i] * p1[i];
		}

		if (lenght1 == 0 || lenght2 == 0)
			return 0;

		return scalar / (lenght1 * lenght2);

	}
	
	public abstract Element agglomerate(Element c1);

}